feat: observe resize segment for better indicator display #565
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Tests in #563 were failing. After debugging, I figured out that the potential display issue actually already existed on the main branch. Specifically, since the segment buttons have no fixed width, depending on the rendering, it's possible that on mount, the buttons are not yet fully rendered—meaning they haven't occupied their full width yet—resulting in the indicator position not being accurately calculated. Similarly, the buttons might be rendered, but the font could take time to load, causing the indicator position to be calculated with the fallback font instead of the final one. Additionally, if the language is changed at runtime, it might result in a change in the buttons' length.
Long story short, observing the size of the container and repositioning the indicator when the size changes ensures that the indicator is always correctly positioned.
Changes
ResizeObserver
to set the indicator position.ResizeObserver
globally for vitestScreenshots
Before on main:
After:
Tests
Tests of #563 should pass.